<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;
use Think\Controller;
class OrderController extends Controller {
  /**
   * 订单列表
   */
  public function OrderListIndex() {
    $adminId = $this->Islogin();
    if(!empty(I('post.getall'))&&I('post.getall')=='aj'){
      $order_db = D('order');
      $order_data = $order_db->ListFieldData(true);
      echo json_encode($order_data['data']);
      return;
    }else{
      $order_db = D('order');
      $order_data = $order_db->ListFieldData(false);
      $admin_mdb = M('admin');
      $adminId   = session('lampzuo_id');
      $admin_res = $admin_mdb -> where('id='.$adminId) -> field('position') -> find();
      // print_r($admin_res);die;
      if($order_data){
        $page = $order_data['page'];
        $this->assign('order_data',$order_data['data']);
        $this->assign('position',$admin_res['position']);
        $this->assign('page',$page->show());
      }
      $this->display('orderlist');
    }
  }

  /**
   * 风控待审核的订单总数
   */
  public function OrderCount(){
     $this->Islogin();
    echo M('order')->where('status=0')->count();
  }

  /**
   * 所有的订单
   */
  public function allOrderList() {
     $this->Islogin();
    $order_db = D('order');
    $order_data = $order_db->AllFkOrder();
    if($order_data){
      $page = $order_data['page'];
      $this->assign('order_data',$order_data['data']);
      $this->assign('page',$page->show());
    }
    $this->display('allorderlist');
  }
  /**
   * 所有的订单
   */
  public function allOrderdata() {
     $this->Islogin();
    $order_db = D('order');
    $order_data = $order_db->AllFkOrder();
    if($order_data){
      $page = $order_data['page'];
      $this->assign('order_data',$order_data['data']);
      $this->assign('page',$page->show());
    }
    $this->display("allorderdatas");
  }
  /**
   * 订单详情
   */
  public function OrderDetailsinfo() {
    $this->Islogin();
    $orderid  = $_GET['orderid'];
    $order_db = D('order');
    $user_db  = D('customer');
    if(!$orderid){
      HttpStatus('404');
    }
    $order_data = $order_db->OrderInfo($orderid);
    $user_data = $user_db->UserInfo($order_data['uid']);
    $income_money_arr = ['1'=>'10001以上','2'=>'8001-10000','3'=>'5001-8000','4'=>'4001-5000','5'=>'3001-4000','6'=>'2001-3000','7'=>'1001-2000','8'=>'1000以下'];
    $incomearr = ['1'=>'自己有房','2'=>'房屋按揭','3'=>'自己租房住','4'=>'和父母同住'];
    $user_data['housingnature'] = $incomearr[$user_data['housingnature']];
    $user_data['income'] = $income_money_arr[$user_data['income']];
    if($user_data){
       $user_data['identify_url']=serializeMysql($user_data['identify_url'],1);
       $user_data['facesign_url']=serializeMysql($order_data['facesign_url'],1);
       $user_data['contract_url']= serializeMysql($order_data['contract_url'],1);
       $user_data['financelease_contract_url']= serializeMysql($order_data['financelease_contract_url'],1);
       $user_data['driver_url']=serializeMysql($user_data['driver_url'],1);
       $user_data['workproof_url']=serializeMysql($user_data['workproof_url'],1);
       $user_data['bankflow_url']=serializeMysql($user_data['bankflow_url'],1);
       $user_data['creditreport_url']=serializeMysql($user_data['creditreport_url'],1);
       $order_data['financelease_url']=serializeMysql($order_data['financelease_url'],1);
       $order_data['mortgagecontract_url']=serializeMysql($order_data['mortgagecontract_url'],1);
       $order_data['policy_url']=serializeMysql($order_data['policy_url'],1);
       $order_data['insurance_url']=serializeMysql($order_data['insurance_url'],1);
       $order_data['purchasetax_url']=serializeMysql($order_data['purchasetax_url'],1);
       $order_data['certificate_url']=serializeMysql($order_data['certificate_url'],1); 
       $order_data['supplementdata_url']=serializeMysql($order_data['supplementdata_url'],1);

       $user_data['entry_url']=serializeMysql($user_data['entry_url'],1);
       $user_data['otherdata_url']=serializeMysql($user_data['otherdata_url'],1);
       $user_data['identify_url']    = getPublicdian($user_data['identify_url']);
       $user_data['driver_url']      = getPublicdian($user_data['driver_url']);
       $user_data['workproof_url']   = getPublicdian($user_data['workproof_url']);
       $user_data['bankflow_url']    = getPublicdian($user_data['bankflow_url']);
       $user_data['creditreport_url']= getPublicdian($user_data['creditreport_url']);
       $user_data['otherdata_url']   = getPublicdian($user_data['otherdata_url']);
       $user_data['entry_url']   = getPublicdian($user_data['entry_url']);

       $order_data['policy_url']=getPublicdian($order_data['policy_url']);
       $order_data['insurance_url']=getPublicdian($order_data['insurance_url']);
       $order_data['purchasetax_url']=getPublicdian($order_data['purchasetax_url']);
       $order_data['certificate_url']=getPublicdian($order_data['certificate_url']);
       $order_data['supplementdata_url']=getPublicdian($order_data['supplementdata_url']);
    }
    $user_data['oss_url']     = C('OSSURL');
    $order_data['weburl_url'] = C('WEBURL').'/';
    $this->assign('order_data',$order_data);
    $this->assign('workproofcount',count($user_data['workproof_url']));
    $this->assign('bankflowcount',count($user_data['bankflow_url']));
    $this->assign('creditreportcount',count($user_data['creditreport_url']));
    $this->assign('facesigncount',count($user_data['facesign_url']));
    $this->assign('otherdatacount',count($user_data['otherdata_url']));
    $this->assign('entrycount',count($user_data['entry_url']));
    $this->assign('policycount',count($order_data['policy_url']));
    $this->assign('insurancecount',count($order_data['insurance_url']));
    $this->assign('purchasetaxcount',count($order_data['purchasetax_url']));
    $this->assign('certificatecount',count($order_data['certificate_url']));
    $this->assign('supplementdatacount',count($order_data['supplementdata_url']));
    $this->assign('user_data',$user_data);
    $this->display('orderdetails');
  }
  
  /**
   * 订单管理数据
   */
  public function adminOrderList() {
    $this->Islogin();
    $order1 = D('Order');
    $data  = session('lampzuo_id');
    $res   = $order1 -> getAdminOrderList($data);
    $this->ajaxReturn($res);
  }
  
  /**
   * 财务返回信息
   */
  public function OrderPayConfirm() {
    $this->Islogin();
    $order_mdb = D('order');
    $order_data = $order_mdb->OrderAlreadyPay();
    $page = $order_data['page'];
    $pages= $page->show();
    $page->setConfig('header','个会员');
    $this->assign('order_data',$order_data['data']);
    $this->assign('show',$pages);
    $this->display('orderpayconfirm');
  }

  /**
   * 财务定金确认
   */
  public function orderDepositConfirm()
  {
    $orderid = I('post.orderid');
    $carnum = I('post.carnum');
    $orderDb = M('order');
    $orderOperationDb = M('order_operation');
    $adminDb = M('admin');
    $id = $orderDb -> where(['orderid' => $orderid]) -> save(['deposit_state' => 2]);
    if ($id) {
        $seid     = session('lampzuo_id');
        $admin = $adminDb -> where(['id' => $seid]) -> find();
        $data = [];
        $data['orderid'] = $orderid;
        // $data['status'] = 0;
        $data['remark'] = '定金确认';
        $data['create_time'] = time();
        $data['usernum'] = $admin['usernum'];
        $result = $orderOperationDb -> add($data);
        exit(json_encode(['success'=>'OK','message'=>'定金确认成功']));
    } else {
        exit(json_encode(['success'=>'error','message'=>'定金确认失败']));
    }
    
  }

  /**
   * 财务返回信息
   */
  public function setOrderDeposit() {
    $this->Islogin();
    $order_mdb = D('order');
    // $order_data = $order_mdb->OrderAlreadyPay();
    // $page = $order_data['page'];
    // $page->setConfig('header','个会员');
    // $this->assign('order_data',$order_data['data']);
    // $this->assign('show',$page->show);
    $this->display('setOrderDeposit');
  }
  /**
   * 财务导出Excle数据
   */
  public  function ExcleFinance(){
    $data = I('post.');
    $order_mdb = D('order');
    $datas=[];
    if($data['exportType'] == 1){
      $order_data = $order_mdb->OrderAlreadyPay();
      foreach($order_data['data'] as $val){
        $data=array();
        $data[]=$val['contract'];
        $data[]=$val['pay_time'];
        $data[]=$val['firstpaymonthpay'];
        $data[]=$val['customername'];
        $data[]=$val['bank'];
        $data[]=$val['banker'];
        $data[]=$val['banknum'];
        $data[]=$val['actionname'];
        $data[]=$val['GWname'];
        $data[]=$val['provinceid'];
        $data[]=$val['cityname'];
        $data[]=$val['orderid'];
        $data[]=$val['cartype'];
        $data[]=$val['jdc_price'];
        $data[]=$val['statustext'];
        $datas[]=$data;
      }
      $filename_n = date('YmdHis');
      $title=['合同编号','支付时间','支付金额','客户姓名','银行名称','银行账户名','银行卡号','手续员姓名','顾问姓名','所属省份','所属城市','订单编号','车型','优优价','状态'];
      $filename_exce = "sheet";
        // 生成Excel并返回文件名称
      $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
      exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！']));
    }else if ($data['exportType'] == 2) {
      $order_data = $order_mdb->OrderHistoryFinance();
      foreach($order_data['data'] as $val){
        $data=array();
        $data[]=$val['orderid'];
        $data[]=$val['cardata']['carnum'];
        $data[]=$val['userdata']['fullanme'];
        $data[]=$val['userdata']['bank'];
        $data[]=$val['userdata']['banker'];
        $data[]=$val['userdata']['banknum'];
        $data[]=$val['cardata']['first_pay'];
        $data[]=$val['cardata']['month_pay'];
        $data[]=$val['orderPaydata']['pay_month'];
        $data[]=$val['orderPaydata']['money'];
        $data[]=$val['orderPaydata']['pay_time'];
        $data[]=$val['cardata']['name'];
        $datas[]=$data;
      }
      $filename_n = date('YmdHis');
      $title=['订单号','车辆编号','客户姓名','银行名称','银行账户名','银行卡号','服务费','月租金','已还期数','下次还款金额','下次还款时间','车辆名称'];
      $filename_exce = "sheet";
      // 生成Excel并返回文件名称
      $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
      exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！']));
    }else if($data['exportType'] == 3){
      $order_data =  $order_mdb->getWaynumMoney();
      foreach($order_data as $val){
        $data=array();
        $data[]=$val['waynum'];
        $data[]=$val['orderid'];
        $data[]=$val['Waystatus']==3?'已关闭':'激活';
        $data[]=$val['name'];
        $data[]=$val['bank'];
        $data[]=$val['banker'];
        $data[]=$val['banknum'];
        $data[]=$val['money'];
        $data[]= $val['status']== 0?'未打款':'已打款';
        $datas[]=$data;
      }
      $filename_n = date('YmdHis');
      $title=['渠道编号','订单号','渠道状态','渠道姓名','渠道银行名称','渠道银行户主','渠道银行卡号','打款金额','打款状态'];
      $filename_exce = "sheet";
      // 生成Excel并返回文件名称
      $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
      exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！']));
    }else if($data['exportType'] == 4){
        $order_data =  $order_mdb->getWaynumList();
        foreach($order_data as $val){
        $data=array();
        $data[]=$val['waynum'];
        $data[]=$val['orderid'];
        $data[]=$val['Waystatus']==3?'已关闭':'激活';
        $data[]=$val['name'];
        $data[]=$val['bank'];
        $data[]=$val['banker'];
        $data[]=$val['banknum'];
        $data[]=$val['money'];
        $data[]= $val['status']== 0?'未打款':'已打款';
        $data[]= $val['username'];
        $datas[]=$data;
      }
      $filename_n = date('YmdHis');
      $title=['渠道编号','订单号','渠道状态','渠道姓名','渠道银行名称','渠道银行户主','渠道银行卡号','打款金额','打款状态','打款人姓名'];
      $filename_exce = "sheet";
      // 生成Excel并返回文件名称
      $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
      exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！']));
    }
  }
  /**
   * 财务历史操作记录
   */
  public function OrderHistoryFinance() {
    $this->Islogin();
    $order_mdb  = D('order');
    $order_data = $order_mdb->OrderHistoryFinance();
    $page = $order_data['page'];
    $page->setConfig('header','个会员');
    $this->assign('order_data',$order_data['data']);
    $this->assign('show',$page->show);
    $this->display('orderhistory');
  }
  /**
   * 财务还款记录
   */
  public function OrderRepayment(){
      $this->Islogin();
      $orderstatus = M("order_pay");
      $user        = M("user");
      $count= $orderstatus->count();// 查询满足要求的总记录数
      $Page = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
      $orderlist   = $orderstatus->order("create_time DESC")->limit($Page->firstRow.','.$Page->listRows)->select();
      foreach ($orderlist as $key => $value) {
          if($value['pay_month'] == "0"){
            $orderlist[$key]['pay_month'] = "(首付)";
          }
          $userlist = $user->where("id = ".$value['uid'])->find();
          $orderlist[$key]['fullanme']  = $userlist['fullanme'];
          $orderlist[$key]['tel']       = $userlist['tel'];
          $orderlist[$key]['banknum']   = $userlist['banknum'];
          $orderlist[$key]['bank']   = $userlist['bank'];
          $orderlist[$key]['pay_time']  = date("Y-m-d",$value['create_time']);
      }
      $this->assign('order_data',$orderlist);
      $this->assign('page',$Page->show());
      $this->display("FC_OrderRepayment");

  }
  /**
   * 订单不同状态显示不同信息
   */
  public function orderInformAtionStatus() {
    $this->Islogin();
    $data   = I('post.');
    $order  = D('Order');
    $res    = $order->getOrderInformAtionStatus($data);
    if($res){
      $result = $order->getModelStatus($res);
    }
    $this->ajaxReturn($result);
  }
  /**
   * 列表
   * @return [type] [description]
   */
    public function establishorder(){
      $this->Islogin();
        $Cars = D('Cars');
        $this->assign('Cars',$Cars->getCarsData());
        $this->display();
    }
    /**
     * 搜索手机号
     */
    public function findUser(){
        $this->Islogin();
        $data = I('post.');
        $User = M('User');
        $order = M('Order');
        $list = $User->where(array('tel'=>$data['tel']))->find();
        if(!$list){
          $usertelarr  = ['nickname'=>$data['tel'],'tel'=>$data['tel'],'create_time'=>time()];
          $list['id'] = $User->add($usertelarr);
        }
        $this->ajaxReturn(array('data'=>$list));
    }
    
    /**
     * 返回修改订单传送的值
     */
    public function saveOrder(){
      $this->Islogin();
      $data = I('post.');
      $order= D('Order');
      $Myinfo    = D('Myinfo');
      $cars=M('qcgl_manage', null);
      $brandDb=M('s_sjzd', null);
      $where  = ['type' => '品牌','isdel'=>'0'];
      $brandData = $brandDb -> where($where) -> field('id, content as brand') -> select();
      $brands = [];
      foreach ($brandData as $k => $v) {
          if (!in_array(['brand' => $v['brand']], $brands)) {
              $brands[$v['id']] = ['brand' => $v['brand']];
            }
      }
      $Myinfos    = $Myinfo->getVehicle(true);
      $AllMyinfo = $Myinfo->getAllVehicle();
      $res       = $order->getSaveOrder($data);
      if ($res) {
        $res['vehicle']= $Myinfos;
        $res['allvehicle'] = $AllMyinfo;
        $res['brand'] = $brands;
        $res['cars'] = $cars->select();
        $this->ajaxReturn($res);
      }
    }
    /**
     * 等待签约订单列表
     */
    public function listOrder(){
      $this->Islogin();
      $order = D("Order");
      $admin = M("admin");
      $id    = session('lampzuo_id');
      $addres = $admin->where(array('id'=>$id))->find();
      $res   = $order->getListOrder($addres);
      $this->ajaxReturn($res);
    }
    /**
     * 订单数据并返回订单
     * @return [array] [res]
     */
    public function getDetaIls(){
      // session("lampzuo_id",null);
      $this->Islogin();
      $data  = I('get.');
      $admin = M("admin");
      $order = D("Order");
      $id    = session('lampzuo_id');
      $addres= $admin->where(array('id'=>$id))->find();
      $res    = $order->getListOrder($addres,$data);
      $result = $order->getModelStatus($res);
      $this->ajaxReturn($result);
    }
    /**
     * 查看订单被驳回原因
     */
    public function getReject(){
       $this->Islogin();
      $data = I("post.");
      $operation = M('order_operation');
      $res = $operation->where(array("orderid"=>$data['orderid'],"status"=>-2))->order("id DESC")->find();
      $this->ajaxReturn($res);
    }
    /**
     * 签约
     */
    public  function getSign(){
      $this->Islogin();
      $data = I('post.');
      $order= D('Order');
      $row  = $order->getPublicSign($data);
      if($row){
        return $this->ajaxReturn($row);
      }
    }
    /**
     * 确认签约
     */
    public function getConfirmSign(){
      $this->Islogin();
      $data     = I('post.');
      $morder   = M('order');
      $tag = false;
      $filename = '';
      $order = $morder->where(array('orderid'=>$data['orderid']))->find();
      $paymentArr = [];
      $facesignArr= [];
      $config['rootPath'] =  './Public/Uploads/payment/'.$order['uid'].'/';
      $path = './Public/Uploads/payment/'.$order['uid'].'/contract_url/';
      if(!is_dir($config['rootPath'])){
          mkdir($config['rootPath']);
          chmod($config['rootPath'], 0777);
      }
      if(!is_dir($path)){
          mkdir($path);
          chmod($path, 0777);
      }
      if($_FILES['prove']){
          $config['subName']  = "prove_url";
          $upload = new \Think\Upload($config);// 实例化上传类
          $info=array();
          foreach ($_FILES['prove']['name'] as $key=>$value){
                $file1=array();
                $file1["prove"]['name']=$value;
                $file1["prove"]['type']=$_FILES['prove']["type"][$key];
                $file1["prove"]['tmp_name']=$_FILES['prove']["tmp_name"][$key];
                $file1["prove"]['error']=$_FILES['prove']["error"][$key];
                $file1["prove"]['size']=$_FILES['prove']["size"][$key];

                $info   =   $upload->upload($file1);
                array_push($paymentArr,$info['prove']['savepath'].$info['prove']['savename']);
            }
        }
      if($_FILES['facesign_img']){
          $config['subName']  = "facesign_url";
          $upload = new \Think\Upload($config);// 实例化上传类
          $info=array();
          foreach ($_FILES['facesign_img']['name'] as $key=>$value){
                $file1=array();
                $file1["facesign_img"]['name']=$value;
                $file1["facesign_img"]['type']=$_FILES['facesign_img']["type"][$key];
                $file1["facesign_img"]['tmp_name']=$_FILES['facesign_img']["tmp_name"][$key];
                $file1["facesign_img"]['error']=$_FILES['facesign_img']["error"][$key];
                $file1["facesign_img"]['size']=$_FILES['facesign_img']["size"][$key];

                $info   =   $upload->upload($file1);
                array_push($facesignArr,$info['facesign_img']['savepath'].$info['facesign_img']['savename']);
            }
        }
      if($_FILES['controlcontract']){
          //给文件重命名，尽量不要起中文名字,如下以时间戳+随机数重命名  
          $filename=time().rand(0,1000);
          $file=$_FILES['controlcontract']; 
          //获取文件的后缀,pathinfo()会以数组的形式返回一个文件的路径信息，其中extension元素则是文件的后缀名  
          $ext=pathinfo($_FILES['controlcontract']['name'])['extension'];
          //最终文件名为  
          $filename=$filename.'.'.$ext;
          if (move_uploaded_file($file['tmp_name'], $path.$filename)) {  
            $tag = true;
          } else{  
            $tag = false;  
          }  
      }
      if($_FILES['contract']){
          //文件重命名，尽量不要起中文名字,如下以时间戳+随机数重命名  
          $names=time().rand(0,1000);
          $file=$_FILES['contract']; 
          //获取文件的后缀,pathinfo()会以数组的形式返回一个文件的路径信息，其中extension元素则是文件的后缀名  
          $ext=pathinfo($_FILES['contract']['name'])['extension'];
          //最终文件名为  
          $names=$names.'.'.$ext;
          if (move_uploaded_file($file['tmp_name'], $path.$names)) {  
            $tag = true;
          } else{  
            $tag = false;  
          }  
      }
      if(!$tag){
        $this->ajaxReturn(array('ret'=>0,"msg"=>"合同上传失败!"));
      }
      $data['paymentArr']   = $paymentArr;
      $data['contract_url'] = $filename;
      $data['financelease_contract_url'] = $names;
      $data['facesign_url'] = $facesignArr;
      $mod = $morder->where(array('contract'=>$data['contract']))->find();
      if($mod){
         $this->ajaxReturn(array('ret'=>0,"msg"=>"对不起合同号已存在!"));
      }
      $orders    = D('order');
      $res = $orders->getQianYue($data);
      if($res['withhold']=="ERROR"){
          $this->ajaxReturn($res);
      }
      if($res['success']=="ERROR"){
          $this->ajaxReturn($res);
      }
      if($res){
        $this->ajaxReturn(array('ret'=>1,"msg"=>"签约成功"));
      }else{
        $this->ajaxReturn(array('ret'=>0,"msg"=>"签约失败"));
      }
    }

    /**
     * 上牌页面加载
     * @return [type] [description]
     */
    public  function getShang(){
      $this->Islogin();
      $data = I('post.');
      $order= D('Order');
      $row  = $order->getPublicSign($data);
      if($row){
        return $this->ajaxReturn($row);
      }
    }

    /**
     * 上牌
     */
    public function getOntheCard(){
      $this->Islogin();
      $data     = I('post.'); 
      $morder   = M('order');
      $order    = D('order');
      $userarr  = array();
      $res_user =$morder->where(array('orderid'=>$data['orderid']))->find();
      $new_file = "./Public/Image/Ceshi/".$res_user['uid']."/";
      if(!file_exists($new_file)){
        $res = chmod($new_file, 0777);
      }
      if($data['baodanArr']){
            $datepath = "Public/Image/Ceshi/".$res_user['id']."/policy_url";
            if(!ossGetObject($datepath))
            {
                //检查是否有该文件夹，如果没有就创建，并给予最高权限
                $res=createObjectDir($datepath);
            }
            foreach ($data['baodanArr'] as $key => $value) {
                  $newj = "./Public/Image/Ceshi/".$res_user['id']."/policy_url/";
                  $result = Base64DecodeImage($value,$newj,createverifycode());
                  ImgThumb($newj.$result);
                  ossPutObject($datepath.'/'.$result,file_get_contents(C('WEBURL').$newj.$result));
                  $data['policy_url'][] = $newj.$result;
                  @unlink(C('PUBLIC_ROUTE').$newj.$result);
                
            }
      }
      if($data['baoxianArr']){
            $datepath = "Public/Image/Ceshi/".$res_user['id']."/insurance_url";
            if(!ossGetObject($datepath))
            {
                //检查是否有该文件夹，如果没有就创建，并给予最高权限
                $res=createObjectDir($datepath);
            }
            foreach ($data['baoxianArr'] as $key => $value) {
                  $newj = "./Public/Image/Ceshi/".$res_user['id']."/insurance_url/";
                  $result = Base64DecodeImage($value,$newj,createverifycode());
                  ImgThumb($newj.$result);
                  ossPutObject($datepath.'/'.$result,file_get_contents(C('WEBURL').$newj.$result));
                  $data['insurance_url'][] = $newj.$result;
                  @unlink(C('PUBLIC_ROUTE').$newj.$result);
                
            }
      }
      if($data['gouzhiArr']){
            $datepath = "Public/Image/Ceshi/".$res_user['id']."/purchasetax_url";
            if(!ossGetObject($datepath))
            {
                //检查是否有该文件夹，如果没有就创建，并给予最高权限
                $res=createObjectDir($datepath);
            }
            foreach ($data['gouzhiArr'] as $key => $value) {
                  $newj = "./Public/Image/Ceshi/".$res_user['id']."/purchasetax_url/";
                  $result = Base64DecodeImage($value,$newj,createverifycode());
                  ImgThumb($newj.$result);
                  ossPutObject($datepath.'/'.$result,file_get_contents(C('WEBURL').$newj.$result));
                  $data['purchasetax_url'][] = $newj.$result;
                  @unlink(C('PUBLIC_ROUTE').$newj.$result);
                
            }
      }
      if($data['hegeArr']){
            $datepath = "Public/Image/Ceshi/".$res_user['id']."/certificate_url";
            if(!ossGetObject($datepath))
            {
                //检查是否有该文件夹，如果没有就创建，并给予最高权限
                $res=createObjectDir($datepath);
            }
            foreach ($data['hegeArr'] as $key => $value) {
                  $newj = "./Public/Image/Ceshi/".$res_user['id']."/certificate_url/";
                  $result = Base64DecodeImage($value,$newj,createverifycode());
                  ImgThumb($newj.$result);
                  ossPutObject($datepath.'/'.$result,file_get_contents(C('WEBURL').$newj.$result));
                  $data['certificate_url'][] = $newj.$result;
                  @unlink(C('PUBLIC_ROUTE').$newj.$result);
                
            }
      }
      $moer     = $morder->where('car_num='.$data['carnum'])->find();
      if($moer){
         $this->ajaxReturn(array('ret'=>0,"msg"=>"车牌号已存在!"));
      }
      $res     = $order->getShangPai($data);
      if($res){
        $this->ajaxReturn(array('ret'=>1,"msg"=>"上牌成功"));
      }else{
        $this->ajaxReturn(array('ret'=>0,"msg"=>"上牌失败"));
      }
    }

    /**
     * 返回查看信息
     */
    public function isGetOrderDetalis(){
      $this->Islogin();
      $data = I('post.');
      $order= D('order');
      $res  = $order->getPublicSign($data);
      if($res){
          $res['create_time'] = date('Y-m-d H:i:s',$res['create_time']);
      }
      $this->ajaxReturn($res);
    }
    /**
     * 图片处理
     * @param  [type] $data   [description]
     * @param  [type] $resuid [description]
     * @return [type]         [description]
     */
    public function webfileupload($data,$resuid){
            $arr    = array();//身份证
            $jszarr = array();//驾驶证
            $gzarr  = array();//工作证明
            $zxarr  = array();//征信报告
            $yharr  = array();//银行流水
            $config = C('DOWNLOAD_UPLOAD');
            $config['rootPath'] =  './Public/Image/Createanorder/'.$resuid.'/';
            if(!is_dir($config['rootPath'])){
                mkdir($config['rootPath']);
            }
            if($data['gzzm']){
              $config['subName']  = "workproof_url";
              $upload = new \Think\Upload($config);// 实例化上传类
              $info=array();
              foreach ($data['gzzm']['name'] as $key=>$value){
                    $file1=array();
                    $file1["gzzm"]['name']=$value;
                    $file1["gzzm"]['type']=$data['gzzm']["type"][$key];
                    $file1["gzzm"]['tmp_name']=$data['gzzm']["tmp_name"][$key];
                    $file1["gzzm"]['error']=$data['gzzm']["error"][$key];
                    $file1["gzzm"]['size']=$data['gzzm']["size"][$key];
                    $info   =   $upload->upload($file1);
                    array_push($gzarr,$config['rootPath'].$info['gzzm']['savepath'].$info['gzzm']['savename']);
                }
            }
            if($data['zx']){
              $config['subName']  =  "creditreport_url";
              $upload = new \Think\Upload($config);// 实例化上传类
              $info=array();
              foreach ($data['zx']['name'] as $key=>$value){
                    $file1=array();
                    $file1["zx"]['name']=$value;
                    $file1["zx"]['type']=$data['zx']["type"][$key];
                    $file1["zx"]['tmp_name']=$data['zx']["tmp_name"][$key];
                    $file1["zx"]['error']=$data['zx']["error"][$key];
                    $file1["zx"]['size']=$data['zx']["size"][$key];
                    $info   =   $upload->upload($file1);
                    array_push($zxarr,$config['rootPath'].$info['zx']['savepath'].$info['zx']['savename']);
                }
            }
            if($data['yhls']){
              $config['subName']  =  "bankflow_url";
              $upload = new \Think\Upload($config);// 实例化上传类
              $info=array();
              foreach ($data['yhls']['name'] as $key=>$value){
                    $file1=array();
                    $file1["yhls"]['name']=$value;
                    $file1["yhls"]['type']=$data['yhls']["type"][$key];
                    $file1["yhls"]['tmp_name']=$data['yhls']["tmp_name"][$key];
                    $file1["yhls"]['error']=$data['yhls']["error"][$key];
                    $file1["yhls"]['size']=$data['yhls']["size"][$key];
                    $info   =   $upload->upload($file1);
                    array_push($yharr,$config['rootPath'].$info['yhls']['savepath'].$info['yhls']['savename']);
                }
            }
            if($data['sfz']){
              $config['subName']  =  "identify_url";
              $upload = new \Think\Upload($config);// 实例化上传类
              $info=array();
              foreach ($data['sfz']['name'] as $key=>$value){
                    $file1=array();
                    $file1["sfz"]['name']=$value;
                    $file1["sfz"]['type']=$data['sfz']["type"][$key];
                    $file1["sfz"]['tmp_name']=$data['sfz']["tmp_name"][$key];
                    $file1["sfz"]['error']=$data['sfz']["error"][$key];
                    $file1["sfz"]['size']=$data['sfz']["size"][$key];
                    $info   =   $upload->upload($file1);
                    array_push($arr,$config['rootPath'].$info['sfz']['savepath'].$info['sfz']['savename']);
                }
            }
            if($data['jsz']){
              $config['subName']  =  "driver_url";
              $upload = new \Think\Upload($config);// 实例化上传类
              $info=array();
              foreach ($data['jsz']['name'] as $key=>$value){
                    $file1=array();
                    $file1["jsz"]['name']=$value;
                    $file1["jsz"]['type']=$data['jsz']["type"][$key];
                    $file1["jsz"]['tmp_name']=$data['jsz']["tmp_name"][$key];
                    $file1["jsz"]['error']=$data['jsz']["error"][$key];
                    $file1["jsz"]['size']=$data['jsz']["size"][$key];
                    $info   =   $upload->upload($file1);
                    array_push($jszarr,$config['rootPath'].$info['jsz']['savepath'].$info['jsz']['savename']);
                }
            }
            $addarr= array(
                "identify_url"      => $arr,
                "driver_url"        => $jszarr,
                "workproof_url"     => $gzarr,
                "bankflow_url"      => $yharr,
                "creditreport_url"  => $zxarr,
              );
        return $addarr;
    }
    
    /**
     * 风控审核通过状态更改
     */
    public function riskEvaluate(){
      $this->Islogin();
      $data = I('post.');
      $order = D('Order');
      $aorder= M('Order')->where(array('orderid'=>$data['orderid']))->find();
      if($aorder['last_update'] != $aorder['create_time']){
        echo "2";die;
      }
      if($data['status']=='-2' || $data['status']=='-1' || $data['status']=='1'){
        $data['reject_remark'] = $data['remark'];
      }
      $res = $order->getSiskEvaluate($data);
      if($res){
         $this->ajaxReturn(array('ret'=>1,'msg'=>"状态操作成功"));
      }else{
         $this->ajaxReturn(array('ret'=>0,'msg'=>"状态操作失败"));
      }
    }

    /*财务核算审核*/
    public function setFinanceAudit(){
      $this->Islogin();
      $data  = I('post.');
      $order = M('Order');
      $admin = M('admin');
      $orderoperation = M('order_operation');
      $seid     = $_SESSION['lampzuo_id'];
      $adminli  = $admin->where(array('id'=>$seid))->find();
      if($data['status'] == "1"){
          $userArr = array(
                    "orderid" => $data['orderid'],
                    "usernum" => $adminli['usernum'],
                    "status"  => 101,
                    "remark"  => $data['remark'],
                    "create_time"=> time(),
          );
          $orderArr = array(
                    'finance'=> $data['status'],
                    'remark'=>"财务通过"
                    );

      }else if($data['status'] == "-2"){
          $userArr = array(
                    "orderid" => $data['orderid'],
                    "usernum" => $adminli['usernum'],
                    "status"  => $data['status'],
                    "remark"  => $data['remark'],
                    "create_time"=> time(),
          );
          $orderArr = array(
                    'status'=> $data['status'],
                    'remark'=>"财务驳回"
                    );
      }
      $res = $order->where(array('orderid'=>$data['orderid']))->save($orderArr);
      if($res){
          $orderoperation->add($userArr);
          $this->ajaxReturn(array('ret'=>1,'msg'=>"状态操作成功"));
      }else{
           $this->ajaxReturn(array('ret'=>0,'msg'=>"状态操作失败"));
      }
    }

    /**
     * 财务确认收款
     */
    public function financeConfirm(){
      $this->Islogin();
      $data = I('post.');
      $order= D('Order');

      $res  = $order->getFinance($data);
      if($res === "6"){
         $this->ajaxReturn(array('ret'=>0,'msg'=>"对不起你不是财务人员无法操作"));
      }else if($res === "2"){
         $this->ajaxReturn(array('ret'=>0,'msg'=>"订单暂未签约。"));
      }
      if($res){
         $this->ajaxReturn(array('ret'=>1,'msg'=>"状态操作成功")); 
      }else{
         $this->ajaxReturn(array('ret'=>0,'msg'=>"状态操作失败"));
      }
    }

  /**
   * 渠道分润列表
   */
  public function channelprofit(){
    $this->Islogin();
    $order_mdb = D('order');
    $arrChannel=  $order_mdb->getWaynumMoney();
    $this->assign('channellist',$arrChannel);
    $this->display('channelprofit');
  }
  /**
   * 修改已打款状态
   */
  public function channelstatus(){
      $data = I('post.');
      $waynum = M('wayuser_pay');
      $admin  = M('admin');
      // $sess = session('lampzuo_id');
      $res = $admin->where(array('id'=>session('lampzuo_id')))->find();
      if(!$res){
        $this->Islogin();
      }
      $arr = array(
        'usernum' => $res['usernum'],
        'status' => $data['status'],
        );
      $res = $waynum->where(array('id'=>$data['id'],'waynum'=>$data['waynum']))->save($arr);
      if($res){
        $this->ajaxReturn(array('success'=>"OK",'status'=>1,'message'=>"操作成功"));
      }else{
        $this->ajaxReturn(array('success'=>"error",'status'=>2,'message'=>"操作失败"));
      }
  }
  /**
   * 已给渠道打款记录
   * @return [type] [description]
   */
  public function channelprofitlist(){
    $order = D('order');
    $adminid = session('lampzuo_id');
    $res = $order->getWaynumList($adminid);
    $this->assign('channellist',$res);
    $this->display();
  }

  /**
   * 消息提醒
   * @return [type] [description]
   */
  public function fkcallseven(){
        $orderremind   = M("order");
        $admin         = M('admin');
        $ordermonthpay = M('order_month_pay');
        $jdcwayuser    = M('wayuser');
        $addres = $orderremind->where("status = 0 or status = 3")->select();
        $adminaddres = $admin->where('id = '.session('lampzuo_id'))->find();
        if($adminaddres['position'] == "503"){
            $addres = $orderremind->where("(status = 0  or status = 3) and thirdparty_audit = 1")->select();
        }
        $datepath = "Public/CallAdmin/Risk";
        if(!ossGetObject($datepath))
        {
            //检查是否有该文件夹，如果没有就创建，并给予最高权限
            $res=createObjectDir($datepath);
        }
        $arr = array(
            'pending'=>0, //等待审核数
            'repayment'=>0, //即将还款数
            'overdue'=>0, //逾期数
            'staymonytype'=>0,//代收款查看
            'admintype'=>$adminaddres['position'],//人员标识判断
            'channelPending'=>0,//渠道待审核
          );
        $paymone = $ordermonthpay->where('status <> 1')->select();
        foreach ($addres as $key => $value) {
            $fileName="Public/CallAdmin/Risk/".$adminaddres['tel'].$value['orderid'].".json";
            $result  = ossGetObject($fileName);
                if(!$result){
                  $data = array(
                    'pending'=>0, //等待审核数
                    'repayment'=>0, //即将还款数
                    'overdue'=>0, //逾期数
                    'staymonytype'=>0,//财务确认收款
                  );
                    if($value['status'] == "3" && $adminaddres['position'] == "6"){
                      $arr['staymonytype'] +=1;
                      $data['staymonytype'] =1;
                    }elseif($value['status'] == "0" || $value['status'] == "7"){
                        $time = time();
                        foreach ($paymone as $ke => $val) {
                          if($val['orderid'] == $value['orderid']){
                            if($val['pay_time'] < $time){
                                  $data['overdue'] = 1;
                                  $arr['overdue'] += 1;
                            }
                            if($val['pay_time']-(7*20*60*60) < $time){
                                  $arr['repayment'] +=1;
                                  $data['repayment'] =1;
                            }
                          }
                        }
                        $data['pending'] =1;
                        $arr['pending'] +=1;
                    }
                  $jsondata = json_encode($data);
                  ossPutObject($fileName,$jsondata);
              }else{
                  $jsonres = json_decode($result,true);
                  if($jsonres){
                      $arr['pending']   += $jsonres['pending'];
                      $arr['repayment'] += $jsonres['repayment'];
                      $arr['overdue']   += $jsonres['overdue'];
                  }
              
            }
        }
        //渠道消息提醒
        $callchenn = $jdcwayuser->where("status=1")->select();
        $channelpath = "Public/CallAdmin/ChannelRisk";
        if(!ossGetObject($channelpath))
        {
            //检查是否有该文件夹，如果没有就创建，并给予最高权限
            $res=createObjectDir($channelpath);
        }
        $channarr = [];
        $fileName="Public/CallAdmin/ChannelRisk/".$adminaddres['tel'].".json";
        $result  = ossGetObject($fileName);
        foreach ($callchenn as $key => $value) {
          if($result){
            $jsonres = json_decode($result,true);
            foreach ($jsonres as $k => $v) {
              if($value['id'] == $v['id']){
                $arr['channelPending'] += $v['channelPending'];
              }
            }
          }else{
            $chenval['id'] = $value['id']; 
            $chenval['channelPending'] = 1;
            $arr['channelPending'] += 1;
            $channarr[] = $chenval;
          }
        }
        if(!$result){
            $jsondata = json_encode($channarr);
            ossPutObject($fileName,$jsondata);
        }
        $this->ajaxReturn($arr);
  }
  public function  editremind(){
    $call = M('order');
    $admin = M('admin');
    $jdcwayuser= M('wayuser');
    $typelist = I("post.data"); 
    $adminaddres = $admin->where('id = '.session('lampzuo_id'))->find();
    $callarr  = $call->select();
    foreach ($callarr as $key => $value) {
        $fileName="Public/CallAdmin/Risk/".$adminaddres['tel'].$value['orderid'].".json";
        $result  = ossGetObject($fileName);
        if($result){
          $jsonres = json_decode($result,true);
          if($result && $typelist == "1"){
              $jsonres['pending'] = 0;
              // $jsonres['pendigtype'] = 1;
          }else if($result && $typelist == "2"){
              $jsonres['repayment'] = 0;  
              // $jsonres['repaymenttype'] = 1;  
          }else if($result && $typelist == "3"){
              $jsonres['overdue'] = 0;  
              // $jsonres['overduetype'] = 1;  
          }else if($result && $typelist == "4"){
              $jsonres['staymonytype'] = 0;  
          }
          $jsondata = json_encode($jsonres);
          ossPutObject($fileName,$jsondata);
        }
    }
    $channName="Public/CallAdmin/ChannelRisk/".$adminaddres['tel'].".json";
    $reschann  = ossGetObject($channName);
    if($reschann){
      $jsonres = json_decode($reschann,true);
      foreach ($jsonres as $key => $value) {
        $jsonres[$key]['channelPending'] = 0;
      }
      $jsondata = json_encode($jsonres);
      ossPutObject($channName,$jsondata);
    }
    
    $this->ajaxReturn($typelist);
  }
  /**
   * [Call O端消息提醒]
   */
  public function Call()
  {
      $id = I('request.id');
      $admin_db = M('admin');
      $order_db = M('order');
      $wayuser_db = M('wayuser');
      $order_operation_db = M('order_operation');
      $order_month_pay_db = M('order_month_pay');
      $admin = $admin_db -> where(array('id' => $id)) -> find();
      switch($admin['position'])
      {
          case 1:
              $orderStatus = "status in (-2,-1,2,3,4,5,6)";
              break;
          case 2:
              $orderStatus = "status in (2,4)";
              break;
          case 3:
              $orderStatus = "status in (1,3,4,5,6)";
              break;
      }
      $path = 'Public/CallAdmin/GW';
      if (!ossGetObject($path)) {
          createObjectDir($path);
      }
      $data = [];$ordersid = '';
      if ($admin['position'] == 1) {
          $order_operation = $order_operation_db -> where(array('usernum' => $admin['usernum'], 'status' => 0)) -> select();
          $ordersid = "orderid in (".implode(',', array_column($order_operation, 'orderid')).")";
          $orders = $order_db -> where($ordersid." and ".$orderStatus) -> select();
          $result = $this -> adminCall($orders, $admin, $path);

          $wayuser = $wayuser_db -> where('admin_id='.$admin['id'].' and status <> 0 and status <> 1') -> select();
          $result2 = $this -> wayCall($admin, $wayuser, $path);

          $data = $result;
          $data['wayStatus'] = $result2;
      } else if ($admin['position'] == 2) {
          $orders = $order_db -> where("provinceid=".$admin['provinceid']." and ".$orderStatus) -> select();
          $result = $this -> adminCall($orders, $admin, $path);
          $data = $result;
      } else if ($admin['position'] == 3) {
          $orders = $order_db -> where("cityid=".$admin['cityid']." and ".$orderStatus) -> select();
          $result = $this -> adminCall($orders, $admin, $path);

          $gws = $admin_db -> where('id='.$admin['pid']) -> select();
          $admin_ids = "admin_id in (".implode(',', array_column($gws, 'id')).") and status == 0";
          $wayuser = $wayuser_db -> where($admin_ids) -> select();
          $result2 = $this -> wayCall($admin, $wayuser, $path);

          $data = $result;
          $data['wayStatus'] = $result2;
      }
      if ($admin['position'] == 4) {
          $orders = $order_db -> where(array('provinceid' => $admin['provinceid'])) -> select();
          $ordersid = "orderid in (".implode(',', array_column($orders, 'orderid')).")";
          $order_month_pay = $order_month_pay_db -> where($ordersid) -> select();
          $count = $this -> orderOverdueCall($orders, $order_month_pay, $admin, $path);
          $data['overdue'] = $count;
      } else if ($admin['position'] == 1) {
          $order_month_pay = $order_month_pay_db -> where($ordersid) -> select();
          $count = $this -> orderOverdueCall($orders, $order_month_pay, $admin, $path);
          $count1 = $this -> orderSevenCall($orders, $order_month_pay, $admin, $path);
          $data['overdue'] = $count;
          $data['seven'] = $count1;
      }
      $this -> ajaxReturn($data, 'JSONP');
  }

  public function wayCall($admin, $wayuser, $path)
  {
      $data = [];$content = []; $tag = true;
      $filename = $path.'/'.$admin['usernum'].$admin['tel'].'.json';
      foreach ($wayuser as $k => $v) {
          if (!doesObjectExist($filename)) {
              $content[$wayuser[$k]['id']] = [];
              $content[$wayuser[$k]['id']][$wayuser[$k]['status']] = 0;
              $data[$wayuser[$k]['status']] += 1;
          } else {
              if ($tag) {
                  $content = json_decode(ossGetObject($filename), true);
              }
              if ($content[$wayuser[$k]['id']][$wayuser[$k]['status']] == 0 && key_exists($wayuser[$k]['status'], $content[$wayuser[$k]['id']])) {
                  $data[$wayuser[$k]['status']] += 1;
              } else if (!key_exists($wayuser[$k]['status'],$content[$wayuser[$k]['id']])) {
                  $content[$wayuser[$k]['id']][$wayuser[$k]['status']] = 0;
                  $data[$wayuser[$k]['status']] += 1;
              }
              $tag = false;
          }
      }
      ossPutObject($filename, json_encode($content));
      return $data;
  }

  public function adminCall($orders, $admin, $path)
  {
      $data = [];
      foreach ($orders as $k => $v) {
          $content = [];
          $filename = $path.'/'.$admin['tel'].$orders[$k]['orderid'].'.json';
          if (!doesObjectExist($filename)) {
              $status = $orders[$k]['status'] == -1 || $orders[$k]['status'] == -2;
              if ((time() - $orders[$k]['create_time']) < 300 && $status) continue;
              $content[$orders[$k]['status']] = 0;
              $data[$orders[$k]['status']] += 1;
              ossPutObject($filename, json_encode($content));
          } else {
              $content = json_decode(ossGetObject($filename), true);
              foreach ($content as $key => $value) {
                  if ($orders[$k]['status'] == $key && $value == 0) {
                      $data[$orders[$k]['status']] += 1;
                  } else if (!key_exists($orders[$k]['status'],$content)) {
                      $data[$orders[$k]['status']] += 1;
                      $content[$orders[$k]['status']] = 0;
                  }
              }
              ossPutObject($filename, json_encode($content));
          }
      }
      return $data;
  }

  public function orderOverdueCall($orders, $order_month_pay, $admin, $path)
  {
      $count = 0;
      foreach ($orders as $key => $value) {
          $overdue = [];
          $filename = $path.'/'.$admin['tel'].$orders[$key]['orderid'].'.json';
          if (!doesObjectExist($filename)) {
              foreach ($order_month_pay as $k => $v) {
                  if ($orders[$key]['orderid'] == $order_month_pay[$k]['orderid']) {
                      if ($order_month_pay[$k]['overdue_status'] == 1) {
                          $overdue[$order_month_pay[$k]['pay_month']] =  0;
                          $count += 1;
                      }
                  }
              }
              ossPutObject($filename, json_encode(['overdue' => $overdue]));
          } else {
              $result = json_decode(ossGetObject($filename), true);
              if (key_exists('overdue', $result)) {
                  $content = $result['overdue'];
                  foreach ($order_month_pay as $k => $v) {
                      if ($orders[$key]['orderid'] == $order_month_pay[$k]['orderid']) {
                          $pay_month = $order_month_pay[$k]['pay_month'];
                          if ($order_month_pay[$k]['overdue_status'] == 1 && !key_exists($pay_month, $content)) {
                              $content[$pay_month] = 0;
                              $count += 1;
                          } else if (key_exists($pay_month, $content) && $content[$pay_month] == 0) {
                              $count += 1;
                          }
                      }
                  }
                  $result['overdue'] = $content;
              } else {
                  $overdue = [];
                  foreach ($order_month_pay as $k => $v) {
                      if ($orders[$key]['orderid'] == $order_month_pay[$k]['orderid']) {
                          $pay_month = $order_month_pay[$k]['pay_month'];
                          if ($order_month_pay[$k]['overdue_status'] == 1) {
                              $overdue[$pay_month] = 0;
                              $count += 1;
                          }
                      }
                  }
                  $result['overdue'] = $overdue;
              }
              ossPutObject($filename, json_encode($result));
          }
      }
      return $count;
  }
  public function orderSevenCall($orders, $order_month_pay, $admin, $path)
  {
        $count = 0;
        foreach ($orders as $key => $value) {
            $overdue = [];
            $filename = $path.'/'.$admin['tel'].$orders[$key]['orderid'].'.json';
            if (!doesObjectExist($filename)) {
                foreach ($order_month_pay as $k => $v) {
                    if ($orders[$key]['orderid'] == $order_month_pay[$k]['orderid']) {
                        $time = $order_month_pay[$k]['pay_time'] - time();
                        if ($time <= 604800 && $time >= 0) {
                            $overdue[$order_month_pay[$k]['pay_month']] =  0;
                            $count += 1;
                        }
                    }
                }
                ossPutObject($filename, json_encode(['seven' => $overdue]));
            } else {
                $result = json_decode(ossGetObject($filename), true);
                if (key_exists('seven', $result)) {
                    $content = $result['seven'];
                    foreach ($order_month_pay as $k => $v) {
                        if ($orders[$key]['orderid'] == $order_month_pay[$k]['orderid']) {
                            $time = $order_month_pay[$k]['pay_time'] - time();
                            $pay_month = $order_month_pay[$k]['pay_month'];
                            if ($time <= 604800 && $time >= 0 && !key_exists($pay_month, $content)) {
                                $content[$pay_month] = 0;
                                $count += 1;
                            } else if (key_exists($pay_month, $content) && $content[$pay_month] == 0) {
                                $count += 1;
                            }
                        }
                    }
                    $result['seven'] = $content;
                } else {
                    $overdue = [];
                    foreach ($order_month_pay as $k => $v) {
                        if ($orders[$key]['orderid'] == $order_month_pay[$k]['orderid']) {
                            $time = $order_month_pay[$k]['pay_time'] - time();
                            $pay_month = $order_month_pay[$k]['pay_month'];
                            if ($time <= 604800 && $time >= 0) {
                                $overdue[$pay_month] = 0;
                                $count += 1;
                            }
                        }
                    }
                    $result['seven'] = $overdue;
                }
                ossPutObject($filename, json_encode($result));
            }
        }
        return $count;
  }

  public function updateCall()
  {
      $id = I('request.id');
      $status = I('request.status');
      $name = I('request.name');
      $admin_db = M('admin');
      $order_db = M('order');
      $wayuser_db = M('wayuser');
      $order_operation_db = M('order_operation');
      $admin = $admin_db -> where(array('id' => $id)) -> find();
      if ($admin['position'] == 1) {
          $order_operation = $order_operation_db -> where(array('usernum' => $admin['usernum'], 'status' => 0)) -> select();
          $ordersid = "orderid in (".implode(',', array_column($order_operation, 'orderid')).")";
          $orders = $order_db -> where($ordersid) -> select();
          $wayuser = $wayuser_db -> where('admin_id='.$admin['id'].' and status <> 0 and status <> 1') -> select();
      } else if ($admin['position'] == 2) {
          $orders = $order_db -> where("provinceid=".$admin['provinceid']) -> select();
      } else if ($admin['position'] == 3) {
          $orders = $order_db -> where("cityid=".$admin['cityid']) -> select();
          $gws = $admin_db -> where('id='.$admin['pid']) -> select();
          $admin_ids = "admin_id in (".implode(',', array_column($gws, 'id')).") and status=1";
          $wayuser = $wayuser_db -> where($admin_ids) -> select();
      } else if ($admin['position'] == 4) {
          $orders = $order_db -> where("provinceid=".$admin['provinceid']) -> select();
      }
      $path = 'Public/CallAdmin/GW';
      $count = 0;
      if ($name == 'order') {
          foreach ($orders as $k => $v) {
              $filename = $path.'/'.$admin['tel'].$orders[$k]['orderid'].'.json';
              if (doesObjectExist($filename)) {
                  $content = json_decode(ossGetObject($filename), true);
                  if (is_array($content[$status])) {
                      foreach ($content[$status] as $key => $value) {
                          $content[$status][$key] = 1;
                          $count += 1;
                      }
                      ossPutObject($filename, json_encode($content));
                      continue;
                  }
                  if (key_exists($status, $content)) {
                      $content[$status] = 1;
                      $count += 1;
                  }
                  ossPutObject($filename, json_encode($content));
              }
          }
      }
      if (($admin['position'] == 1 || $admin['position'] == 3) && $name == 'wayuser') {
          $filename = $path.'/'.$admin['usernum'].$admin['tel'].'.json';
          if (doesObjectExist($filename)) {
              $content = json_decode(ossGetObject($filename), true);
              foreach ($wayuser as $k => $v) {
                  if ($content[$wayuser[$k]['id']][$status] == 0 && key_exists($status, $content[$wayuser[$k]['id']])) {
                      $content[$wayuser[$k]['id']][$status] = 1;
                      $count += 1;
                  }
              }
              ossPutObject($filename, json_encode($content));
          }
      }
      $this -> ajaxReturn(['status' => $status, 'count' => $count, 'msg' => $name], 'JSONP');
    }

    public function getApplyRefund()
    {
        $uid = I('request.uid');
        $position = I('request.position');
        $tel = I('request.tel');

        $orderModel = D('order');
        if ($tel) {
            $result = $orderModel -> getApplyRefund(['tel' => $tel]);
            $this -> assign('orders', $result);
            $this -> display('orderrefund');
        } else {
            $result = $orderModel -> getApplyRefund(['id' => $uid]);
            if ($result) {
                $this -> ajaxReturn(['status' => 'success', 'msg' => $result], 'JSON');
            } else {
                $this -> ajaxReturn(['status' => 'error', 'msg' => '暂无数据'], 'JSON');
            }
        }
        
    }

    public function setApplyRefund()
    {
        $orderid = I('request.orderid');
        $status = I('request.status');
        $remark = I('request.remark');
        $tel = I('request.tel');

        $orderDb = M('order');
        $refundOperationDb = M('refund_operation');
        $data = [];
        $data['apply_refund'] = $status;
        $admin = M('admin') -> where(['tel' => $tel]) -> find();
        if (!$admin['pid'] && $admin['position'] == 1) {
            $data['apply_refund'] = 3;
        }
        $result = $orderDb -> where(['orderid' => $orderid]) -> save($data);
        if ($result) {
            $operation = [];
            $operation['orderid'] = $orderid;
            $operation['status'] = $status;
            $operation['remark'] = $remark;
            $operation['usernum'] = $admin['usernum'];
            $operation['create_time'] = time();
            $refundOperationDb -> add($operation);
            $msg = $status <= 0 ? '驳回成功' : '通过成功';
            $this -> ajaxReturn(['status' => 'success', 'msg' => $msg]);
        } else {
            $msg = $status <= 0 ? '驳回失败' : '通过失败';
            $this -> ajaxReturn(['status' => 'error', 'msg' => $msg]);
        }
    }

    /** 申请调车列表 */
    public function setVechlav(){
        $post  = I('get.');
        $order = M('order');
        $admin = M('admin');
        $stock = M('cars_stock');
        $apply = M('apply_dispatch');
        $orderoperation = M('order_operation');
        $adminres = $admin->where(array('id'=>$post['uid']))->find();
        $where   = "status = 0 and usernum = "."'".$adminres['usernum']."'";
        $datares = $orderoperation->where($where)->select();
        $orderid = implode(',', array_column($datares, 'orderid'));
        $where   = "shunting_status <> 2 and  apply_refund in (-1,0) and stockid <> 0 and status = 5 and status <> -1 and orderid in (".$orderid.")";
        $orderres= $order
                    ->join('jdc_cars_stock ON jdc_order.stockid = jdc_cars_stock.id')
                    ->join('qcgl_manage ON jdc_order.carid = qcgl_manage.id')
                    ->join('jdc_user ON jdc_order.uid = jdc_user.id')
                    ->where($where)->select();
        foreach ($orderres as $key => $value) {
              $orderres[$key]['shuntingType'] = 1;
              if($adminres['sid'] == $value['sid']){
                unset($orderres[$key]);
              }
        }
        $apparr = $apply->where(array('status'=>1))->select();
        $apporderid = implode(',', array_column($apparr, 'orderid'));
        $appwhere   = "apply_refund in (-1,0) and stockid <> 0 and status = 5 and status<>-1 and orderid in (".$apporderid.")";
         $apporderres= $order
                    ->join('jdc_cars_stock ON jdc_order.stockid = jdc_cars_stock.id')
                    ->join('qcgl_manage ON jdc_order.carid = qcgl_manage.id')
                    ->join('jdc_user ON jdc_order.uid = jdc_user.id')
                    ->where($appwhere)->select();
        foreach ($apporderres as $key => $value) {
              $apporderres[$key]['pid'] = $adminres['pid'];
              if($adminres['sid'] != $value['sid']){
                unset($apporderres[$key]);
              }
        }
        $this->ajaxReturn(array('data'=>$orderres,'datares'=>$apporderres));
        // var_dump($orderres,'llll');die;
    }
    /*申请调车*/
    public function setOrderVechlav(){
      $get       =I('get.');
      $apply     = M('apply_dispatch');
      $sessid    =session('lampzuo_id');
      $orser     = M('order');
      $stockdata = M('stock_details');
      $resorder  = $orser->where(array('orderid'=>$get['orderid']))->find();
      if($resorder['sdid'] == 0){
          $result= $stockdata->where(array('stock_id'=>$resorder['stockid']))->find();
          $resorder['sdid'] = $result['id'];
      }
      $arr = [
        'apply_aid'=>$sessid,
        'orderid'=>$resorder['orderid'],
        'stockid'=>$resorder['stockid'],
        'sdid'=> $resorder['sdid'],
        'apply_desc'=>$get['remark'],
        'status'=>1,
        'create_time'=>time(),
      ];
      $res = $apply->add($arr);
      if($res){
        $orser->where(array('orderid'=>$get['orderid']))->save(array('shunting_status'=>1));
        $this->ajaxReturn(array('success'=>"ok",'msg'=>"申请成功"));
      }else{
        $this->ajaxReturn(array('success'=>"error",'msg'=>"申请失败"));

      }
    }

    /**确认发车和确认收到车*/
    public function setStartCollectvehicle(){
      $get = I('get.');
      $sessid    =session('lampzuo_id');
      $apply     = M('apply_dispatch');
      $sessid    =session('lampzuo_id');
      $orser     = M('order');
      $stockdata = M('stock_details');
      if($get['vehiclestatus'] == '2'){
        $arr = [
            'sure_aid'=>$sessid,
            'send_desc'=>$get['remark'],
            'status'=>2,
            'send_time'=>time(),
          ];
      }elseif($get['vehiclestatus'] == '1'){
        $resstatus = $apply ->where(array('orderid'=>$get['orderid'],'status'=>2))->find();
        if(!$resstatus){
          $this->ajaxReturn(['success'=>"error",'msg'=>'对方暂未发车']);
        }
        $arr = [
            'sure_aid'=>$sessid,
            'status'=>3,
            'finish_time'=>time(),
          ];
      }
      $res = $apply ->where(array('orderid'=>$get['orderid']))->save($arr);
      $orser->where(array('orderid'=>$get['orderid']))->save(array('shunting_status'=>2));
      if($res){
        $this->ajaxReturn(['success'=>"ok",'msg'=>'更新成功']);
      }else{
        $this->ajaxReturn(['success'=>"error",'msg'=>'更新失败']);
      }
    }
    /*产品核算*/
    public function getAdjustAccounts(){
        $adminId = $this->Islogin();
        if(!empty(I('post.getall'))&&I('post.getall')=='aj'){
          $order_db = D('order');
          $order_data = $order_db->ListFieldData(true);
          echo json_encode($order_data['data']);
          return;
        }else{
          $order_db = D('order');
          $order_data = $order_db->ListFieldData(false);
          if($order_data){
            $page = $order_data['page'];
            $this->assign('order_data',$order_data['data']);
            $this->assign('page',$page->show());
          }
          $this->display('orderadjustaccounts');
        }
    }
    /*核算详情*/
    public function getAdjustDetails() {
      $this->Islogin();
      $orderid  = $_GET['orderid'];
      $order_db = D('order');
      $user_db  = D('customer');
      if(!$orderid){
        HttpStatus('404');
      }
      $order_data = $order_db->OrderInfo($orderid);
      $user_data = $user_db->UserInfo($order_data['uid']);
      $income_money_arr = ['1'=>'10001以上','2'=>'8001-10000','3'=>'5001-8000','4'=>'4001-5000','5'=>'3001-4000','6'=>'2001-3000','7'=>'1001-2000','8'=>'1000以下'];
      $incomearr = ['1'=>'自己有房','2'=>'房屋按揭','3'=>'自己租房住','4'=>'和父母同住'];
      $user_data['housingnature'] = $incomearr[$user_data['housingnature']];
      $user_data['income'] = $income_money_arr[$user_data['income']];
      if($user_data){
         $user_data['identify_url']=serializeMysql($user_data['identify_url'],1);
         $user_data['driver_url']=serializeMysql($user_data['driver_url'],1);
         $user_data['workproof_url']=serializeMysql($user_data['workproof_url'],1);
         $user_data['bankflow_url']=serializeMysql($user_data['bankflow_url'],1);
         $user_data['creditreport_url']=serializeMysql($user_data['creditreport_url'],1);
         $user_data['entry_url']=serializeMysql($user_data['entry_url'],1);
         $user_data['otherdata_url']=serializeMysql($user_data['otherdata_url'],1);
         $user_data['identify_url']    = getPublicdian($user_data['identify_url']);
         $user_data['driver_url']      = getPublicdian($user_data['driver_url']);
         $user_data['workproof_url']   = getPublicdian($user_data['workproof_url']);
         $user_data['bankflow_url']    = getPublicdian($user_data['bankflow_url']);
         $user_data['creditreport_url']= getPublicdian($user_data['creditreport_url']);
         $user_data['otherdata_url']   = getPublicdian($user_data['otherdata_url']);
         $user_data['entry_url']   = getPublicdian($user_data['entry_url']);
      }
      $order_data['nickname'] = $user_data['nickname'];
      $order_data['sex'] = $user_data['sex'];
      $user_data['oss_url'] = C('OSSURL');
      $this->assign('order_data',$order_data);
      $this->assign('workproofcount',count($user_data['workproof_url']));
      $this->assign('bankflowcount',count($user_data['bankflow_url']));
      $this->assign('creditreportcount',count($user_data['creditreport_url']));
      $this->assign('otherdatacount',count($user_data['otherdata_url']));
      $this->assign('entrycount',count($user_data['entry_url']));
      $this->assign('user_data',$user_data);
      $this->display('orderAdjustDetails');
    }
    /*订单合同上传*/
    public function  getUploadContract(){
        $POST = I('post.');
        print_r($POST);die;
    }

    // 获取订单进度信息
    public function getOrderProgress()
    {
        $orderid = I('request.orderid');
        $adminDb = M('admin');
        $orderDb = M('order');
        $orderOperationDb = M('order_operation');
        $order = $orderDb -> where(['orderid' => $orderid]) -> find();
        $data = [];
        if ($order) {
            $str = "'创建订单'";
            $where = 'orderid = '.$orderid.' and remark = '.$str.' and status = 0';
            $orderOperation = $orderOperationDb -> where($where) -> find();
            $admin = $adminDb -> where(['usernum' => $orderOperation['usernum']]) -> find();
            $result = [];
            $result[] = '创建订单';
            $result[] = $admin['name'];
            $result[] = '通过';
            $result[] = date('Y-m-d H:i:s', $orderOperation['create_time']);
            $result[] = '';
            $result[] = true;
            $data[] = $result;
        }
        if ($order['deposit_state'] >= 1) {
            $result = [];
            $admins = $this -> getAdminData($adminDb, 6);
            $str = "'定金确认'";
            $where = 'orderid = '.$orderid.' and usernum in ('.$admins['usernumId'].') and remark = '.$str;
            $orderOperation = $orderOperationDb -> where($where) -> find();
            if ($orderOperation) {
                $result[] = '财务确认定金';
                $result[] = $admins['adminData'][$orderOperation['usernum']]['name'];
                $result[] = '通过';
                $result[] = date('Y-m-d H:i:s', $orderOperation['create_time']);
                $result[] = true;
            } else {
                $result[] = '财务确认定金';
                $result[] = $admins['adminName'];
                $result[] = '未处理';
                $result[] = '';
                $result[] = false;
            }
            $data[] = $result;
        }
        if ($order['buy_type'] != 4) {
            $result = [];
            $admins = $this -> getAdminData($adminDb, 6);
            if ($order['finance'] >= 1) {
                $where = 'orderid = '.$orderid.' and usernum in ('.$admins['usernumId'].') and status = 101';
                $result = $this -> getOperationData($orderOperationDb, $where, '财务核算', '通过', $admins);
            } else {
                $where = 'orderid = '.$orderid.' usernum in ('.$admins['usernumId'].') status = -2';
                $result = $this -> getfailOperationData($orderOperationDb, $where, '财务核算', $admins);
            }
            $data[] = $result;
            $result = [];
            $admins = $this -> getAdminData($adminDb, 502);
            if ($order['thirdparty_audit'] >= 1) {
                $where = 'orderid = '.$orderid.' and  usernum in ('.$admins['usernumId'].') and status = 1';
                $result = $this -> getOperationData($orderOperationDb, $where, '风控审核', '通过', $admins);
            } else {
                $where = 'orderid = '.$orderid.' and usernum in ('.$admins['usernumId'].') and status = -2';
                $result = $this -> getfailOperationData($orderOperationDb, $where, '风控审核', $admins);
            }
            $data[] = $result;
            $result = [];
            $admins = $this -> getAdminData($adminDb, 503);
            if ($order['status'] >= 2) {
                $where = 'orderid = '.$orderid.' and usernum in ('.$admins['usernumId'].') and status = 1';
                $result = $this -> getOperationData($orderOperationDb, $where, '风控经理审核', '通过', $admins);
            } else {
                $where = 'orderid = '.$orderid.' and usernum in ('.$admins['usernumId'].') and status = -2';
                $result = $this -> getfailOperationData($orderOperationDb, $where, '风控经理审核', $admins);
            }
            $data[] = $result;
        }
        $result = [];
        if ($order['status'] >= 3) {
            $str = "'创建订单'";
            $where = 'orderid = '.$orderid.' and status = 0 and remark = '.$str;
            $orderOperation = $orderOperationDb -> where($where) -> find();
            $admin = $adminDb -> where(['usernum' => $orderOperation['usernum']]) -> find();
            $result[] = '签约';
            $result[] = $admin['name'];
            $result[] = '通过';
            $result[] = date('Y-m-d H:i:s', $orderOperation['create_time']);
            $result[] = '';
            $result[] = true;
        } else {
            $str = "'创建订单'";
            $where = 'orderid = '.$orderid.' and status = 0 and remark = '.$str;
            $orderOperation = $orderOperationDb -> where($where) -> find();
            $admin = $adminDb -> where(['usernum' => $orderOperation['usernum']]) -> find();
            $result[] = '签约';
            $result[] = $admin['name'];
            $result[] = '未处理';
            $result[] = '';
            $result[] = '';
            $result[] = false;
        }
        $data[] = $result;
        $result = [];
        $admins = $this -> getAdminData($adminDb, 6);
        if ($order['status'] >= 4) {
            $where = 'orderid = '.$orderid.' and usernum in ('.$admins['usernumId'].') and status = 4';
            $result = $this -> getOperationData($orderOperationDb, $where, '财务确认收款', '通过', $admins);
        } else {
            $result[] = '财务确认收款';
            $result[] = $admins['adminName'];
            $result[] = '未处理';
            $result[] = '';
            $result[] = '';
            $result[] = false;
        }
        $data[] = $result;
        $result = [];
        $admins = $this -> getAdminData($adminDb, 9);
        if ($order['status'] >= 5) {
            $where = 'orderid = '.$orderid.' and usernum in ('.$admins['usernumId'].') and status = 5';
            $result = $this -> getOperationData($orderOperationDb, $where, '上牌', '通过', $admins);
        } else {
            $result[] = '上牌';
            $result[] = $admins['adminName'];
            $result[] = '未处理';
            $result[] = '';
            $result[] = '';
            $result[] = false;
        }
        $data[] = $result;
        $result = [];
        if ($order['apply_refund'] > 0) {
            $admins = $this -> getAdminData($adminDb, 6);
            $refundDb = M('refund_operation');
            $where = 'orderid ='.$orderid.' and usernum in ('.$admins['usernumId'].')';
            $refund = $refundDb -> where($where) -> order('create_time desc') -> find();
            $result[] = '退款申请';
            $result[] = $refund ? $admins['adminData'][$refund['usernum']]['name'] : $admins['adminName'];
            $result[] = $refund ? $refund['status'] >= 1 ? '退款申请中' : '驳回' : '未处理'; 
            $result[] = $refund ? date('Y-m-d', $refund['create_time']) : '';
            $result[] = '';
        }
        $this -> ajaxReturn($data, 'json');
    }

    public function getAdminData($adminDb, $position)
    {   
        $admin = $adminDb -> where(['position' => $position]) -> select();
        $adminData = [];
        $usernumId = '';
        $adminName = '';
        foreach ($admin as $k => $v) {
            $usernumId .= $usernumId == '' ? "'".$v['usernum']."'" : ','."'".$v['usernum']."'";
            $adminData[$v['usernum']] = $v;
            $adminName .= $adminName == '' ? $v['name'] : ','.$v['name'];
        }
        return ['adminData' => $adminData, 'usernumId' => $usernumId, 'adminName' => $adminName];
    }
    
    // 获取通过信息
    public function getOperationData($orderOperationDb, $where, $msg, $status, $admins)
    {   
        $result = [];
        $orderOperation = $orderOperationDb -> where($where) -> order('create_time desc') -> find();
        $result[] = $msg;
        $result[] = $admins['adminData'][$orderOperation['usernum']]['name'];
        $result[] = $status;
        $result[] = date('Y-m-d H:i:s', $orderOperation['create_time']);
        $result[] = '';
        $result[] = true;
        return $result;
    }

    public function getfailOperationData($orderOperationDb, $where, $msg,  $admins)
    {   
        $result = [];
        $orderOperation = $orderOperationDb -> where($where) -> order('create_time desc') -> find();
        $result[] = $msg;
        $result[] = $orderOperation ? $admins['adminData'][$orderOperation['usernum']]['name'] : $admins['adminName'];
        if ($orderOperation && $orderOperation['status'] == -2) {
            $result[] = '驳回';
        } else if ($orderOperation && $orderOperation['status'] == -1) {
            $result[] = '拒绝';
        } else {
            $result[] = '未处理';
        }
        $result[] = $orderOperation ? date('Y-m-d H:i:s', $orderOperation['create_time']) : '';
        $result[] = $orderOperation ? $orderOperation['remark'] : '';
        if ($orderOperation && $orderOperation['status'] == -2) {
            $result[] = true;
        } else if ($orderOperation && $orderOperation['status'] == -1) {
            $result[] = true;
        } else {
            $result[] = false;
        }
        return $result;
    }

    public function ordercontractadd(){
      $getid = I("get.id");
      $order = M('Order');
      $orderid = $order->where(['id'=>$getid])->find();
      $this->assign('order',$orderid);
      $this->display('ordercontractadd');
    }
    public function setContractadd(){
      $getid = I("post.");
      $order = M('Order');
      $orderdata  = $order->where(['id'=>$getid['order_id']])->find();
      $path = './Public/Uploads/payment/'.$orderdata['uid'].'/financelease_url/';
      if(!is_dir($path)){
          mkdir($path,0777,true);
      }
      $tag = false;
      if($_FILES['financeleaseurl']){
          //给文件重命名，尽量不要起中文名字,如下以时间戳+随机数重命名  
          $name=time().rand(0,1000);
          $file=$_FILES['financeleaseurl']; 
          //获取文件的后缀,pathinfo()会以数组的形式返回一个文件的路径信息，其中extension元素则是文件的后缀名  
          $ext=pathinfo($_FILES['financeleaseurl']['name'])['extension'];
          //最终文件名为  
          $name=$name.'.'.$ext;
          if (move_uploaded_file($file['tmp_name'], $path.$name)) {  
            $tag = true;
          } else{  
            $tag = false;  
          }  
      }
      if($_FILES['mortgagecontracturl']){
          //给文件重命名，尽量不要起中文名字,如下以时间戳+随机数重命名  
          $filename=time().rand(0,1000);
          $file=$_FILES['mortgagecontracturl']; 
          //获取文件的后缀,pathinfo()会以数组的形式返回一个文件的路径信息，其中extension元素则是文件的后缀名  
          $ext=pathinfo($_FILES['mortgagecontracturl']['name'])['extension'];
          //最终文件名为  
          $filename=$filename.'.'.$ext;
          if (move_uploaded_file($file['tmp_name'], $path.$filename)) {  
            $tag = true;
          } else{  
            $tag = false;  
          }  
      }
      if(!$tag){
        $this->ajaxReturn(['success'=>"error",'msg'=>"模板合同上传失败"]); 
      }
      $data['financelease_url'] = serializeMysql($path.$name);
      $data['mortgagecontract_url'] = serializeMysql($path.$filename);
      $orderid = $order->where(['id'=>$getid['order_id']])->save($data);
      if($orderid){
        $this->ajaxReturn(['success'=>"OK",'msg'=>"上传成功"]); 
      }else{
        $this->ajaxReturn(['success'=>"error",'msg'=>"模板合同上传失败"]); 
      }
    }

    public function setSupplementadd(){
      $getid = I("post.");
      $order = M('Order');
      $facesignArr = [];
      $orderdata  = $order->where(['orderid'=>$getid['order_id']])->find();
      $config['rootPath'] = './Public/Uploads/payment/'.$orderdata['uid'].'/';
      if(!is_dir($config['rootPath'])){
          mkdir($config['rootPath'],0777,true);
      }
      if($_FILES['prove']){
          $config['subName']  = "supplementdata_url";
          $upload = new \Think\Upload($config);// 实例化上传类
          $info=array();
          foreach ($_FILES['prove']['name'] as $key=>$value){
                $file1=array();
                $file1["prove"]['name']=$value;
                $file1["prove"]['type']=$_FILES['prove']["type"][$key];
                $file1["prove"]['tmp_name']=$_FILES['prove']["tmp_name"][$key];
                $file1["prove"]['error']=$_FILES['prove']["error"][$key];
                $file1["prove"]['size']=$_FILES['prove']["size"][$key];
                $info   =   $upload->upload($file1);
                array_push($facesignArr,$config['rootPath'].'/'.$info['prove']['savepath'].$info['prove']['savename']);
            }
        }
      $data['supplementdata_url'] = serializeMysql($facesignArr);
      $orderid = $order->where(['orderid'=>$getid['order_id']])->save($data);
      if($orderid){
        $this->ajaxReturn(['success'=>"OK",'msg'=>"上传成功"]); 
      }else{
        $this->ajaxReturn(['success'=>"error",'msg'=>"上传失败"]); 
      }
    }  
    public function orderProgress()
    {   
        $orderid = I('request.orderid');
        $this -> assign('orderid', $orderid);
        $this -> display('order-progress');

    }
    public  function download(){
      $file = I("get.pdfdata");
      $files = time().rand(1,1000);
      header('Content-type: application/pdf');
      header("Content-Type: application/force-download");
      $files=basename($files);
      //设置文件加载方式为激活下载框
      header('Content-Disposition: attachment; filename='.$files.'.pdf'); 
      readfile($file);
    }
}